// Copyright 2010 Alexandre Tristan St-Cyr <tristan.stcyr@gmail.com>

package com.codeplex.loadjava;

import java.io.PrintStream;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

class LoggingHandler extends Handler {

	@Override
	public void close() throws SecurityException {}

	@Override
	public void flush() {}

	@Override
	public void publish(LogRecord record) {
		Level level = record.getLevel();
		PrintStream out;
		if (level == Level.SEVERE || level == Level.WARNING) {
			out = System.err;
		} else {
			out = System.out;
		}
		out.println(level+": "+record.getMessage());
		Throwable thrown = record.getThrown();
		if (thrown != null)
			thrown.printStackTrace(out);
	}
}
